package com.schematic.flixel.spaceinvaders
{
import org.flixel.FlxSprite;
import org.flixel.FlxG;
import org.flixel.FlxEmitter;

/**
 * Creates an alien sprite
 */
public class Invader extends FlxSprite
{
    //--------------------------------------------------------------------------
    //
    // Constructor
    //
    //--------------------------------------------------------------------------

    /**
     * Creates a new instance of this class.
     */
    public function Invader(x:Number=0, y:Number=0, skin:Class=null)
    {
        super(x, y);
        loadGraphic(skin, true, false, 44, 44);
        addAnimation("one", [0], 1, false);
        addAnimation("two", [1], 1, false);
        play("one");
    }

    //--------------------------------------------------------------------------
    //
    //  Variables
    //
    //--------------------------------------------------------------------------

    //----------------------------------
    //  currentFrame
    //----------------------------------
    /**
     *  @private
     */
    private var currentFrame:int = 1;

    //--------------------------------------------------------------------------
    //
    //  Overridden Methods - FlxObject
    //
    //--------------------------------------------------------------------------
    
    override public function kill():void
    {
        FlxG.state.add(new Explosion(origin.x + x, origin.y + y));
        FlxG.play(Sounds.EXPLOSION_INVADER);
        super.kill();
    }
    
    //--------------------------------------------------------------------------
    //
    //  Methods
    //
    //--------------------------------------------------------------------------

    //----------------------------------
    //  flip
    //----------------------------------
    /**
     * Toggles the animation between frames 1 and 2
     */
    public function flip():void
    {
        if (currentFrame == 1)
        {
            play("two")
            currentFrame = 2;        
        }
        else
        {
            play("one");
            currentFrame = 1;
        }
    } 
}
}